<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>客户端query请求</title>
</head>
<body>
    <button onclick="getData()">获取请求</button>

    <script>
        function getData() {
            const query = `
                query Account($userName: String,$city: String) {
                    account(userName: $userName) {
                        name
                        age
                        sex
                        department
                        salary(city: $city)
                    }
                }
            `

            const variables = { userName: '李四', city: '重庆'}

            fetch("/graphql", {
                method: "POST",
                headers: {
                    'Content-Type': 'application/json',
                    'Accept': 'application/json'
                },
                body: JSON.stringify({
                    query: query,
                    variables: variables
                })
            }).then(res => console.log(res.json))
        }
    </script>
</body>
</html>